package com.iafme.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.zhxu.bs.BeanSearcher;
import cn.zhxu.bs.SearchResult;
import cn.zhxu.bs.operator.Equal;
import cn.zhxu.bs.util.MapUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.RedemptionReqDTO;
import com.iafme.dto.res.RedemptionResDTO;
import com.iafme.service.RedemptionService;
import com.systemframework.annotation.OperateAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.enums.BusinessType;
import com.systemframework.util.Result;
import com.systemframework.util.SearchUtl;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * @author summer
 * @version 1.0
 * @date 2025/4/15 15:16
 */
@RestController
@RequestMapping(value = "/redemption")
@AllArgsConstructor
public class RedemptionController implements BaseCommonInterface<RedemptionReqDTO, RedemptionResDTO> {

    private final RedemptionService redemptionService;

    @SaCheckPermission({"member:redemption:add"})
    @OperateAnnotation(businessType = BusinessType.INSERT,name = "兑换码")
    @Override
    public Result<String> save(@Valid RedemptionReqDTO redemptionReqDTO) {
        redemptionService.saveRedemption(redemptionReqDTO);
        return Result.successResult();
    }

    @Override
    public Result<String> update(@Valid RedemptionReqDTO redemptionReqDTO) {
        return null;
    }

    @Override
    public Result<String> del(Integer integer) {
        return null;
    }

    private final BeanSearcher beanSearcher;

    @Override
    public Result<Page<RedemptionResDTO>> lists(RedemptionReqDTO redemptionReqDTO) {
        Map<String, Object> build = MapUtils.builder().page(redemptionReqDTO.getPageNum() - 1, redemptionReqDTO.getPageSize())
                .field(RedemptionResDTO::getCode, redemptionReqDTO.getCode()).op(Equal.class).build();
        return Result.successResult(SearchUtl.searchDataList(redemptionReqDTO.getPageNum(), redemptionReqDTO.getPageSize(),beanSearcher.search(RedemptionResDTO.class, build)));
    }

    @Override
    public Result<RedemptionResDTO> findById(Integer integer) {
        return null;
    }

    @Override
    public Result<String> batchDel(List<RedemptionResDTO> list) {
        return null;
    }
}
